﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WapCrawlerLib;

namespace WapCrawler.PostCrawler.ucControls
{
    public partial class ucPostCrawlerGridView : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void PostCrawlerLinqDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
        {
            if (Session["wapCrawler"] != null && Session["topicCrawler"] != null)
            {
                WapCrawlerLib.PostCrawler objPostCrawler = new WapCrawlerLib.PostCrawler();
                e.Result = objPostCrawler.FilterByTopicId((int)Session["topicCrawler"]);
            }
        }

        protected void PostCrawlerGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int postCrawlerId = (int)PostCrawlerGridView.DataKeys[e.Row.RowIndex].Value;

                WapDataClassesDataContext dc = new WapDataClassesDataContext();

                var query = from p in dc.TopicPostCrawlers
                            where p.postCrawlerId == postCrawlerId
                            select p.topicCrawlerId;
                if (query != null)
                {
                    PlaceHolder pl = e.Row.FindControl("PlaceHolder1") as PlaceHolder;
                    foreach (int topicCrawlerId in query)
                    {
                        TopicCrawler objTopic = dc.TopicCrawlers.Single(q => q.topicCrawlerId == topicCrawlerId);
                        HyperLink hyperLinkCat = new HyperLink();
                        hyperLinkCat.Text = objTopic.topicName;
                        pl.Controls.Add(hyperLinkCat);
                        pl.Controls.Add(new LiteralControl("&nbsp;-&nbsp;"));
                    }
                }
            }
        }
    }
}